package menu;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Vector;

import core.Constants;
import core.actions.Action;

import menu.ConfigurationMenu.MenuSelectionStatus;

public class MenuAction {
	private String shownName="Default";
	private String actionName="Default";
	private Color color=Color.magenta;
	
	public enum MenuActionType{BROWSE, SELECT_ACTION, EQUIP_STEP_ONE, EQUIP_STEP_TWO, 
		MAIN, ADD_RADIUS, REDUCE_RADIUS, ADD_DEPTH, REDUCE_DEPTH, SET_DEFAULT_ACTION_MAP, NEXT_UNIT, CHANGE_COLOR};
	private MenuActionType type;
	
	
	public MenuAction(){
		shownName="Main";
		actionName="Main";
		color=Color.magenta;
		type=MenuActionType.MAIN;
	}
	public MenuAction(String name, MenuActionType type){
		actionName=name;
		shownName=name;
		
		this.type=type;
	}
	public MenuAction(String actionName, String shownName, MenuActionType type){
		this.actionName=actionName;
		this.shownName=shownName;
		
		this.type=type;
	}
	
	public void activate(PlayerMenu pm){
		switch(type){
		case MAIN:
			MenuController.setMainMenu(pm);
			break;
		case BROWSE:
			MenuController.setBrowseMenu(pm, actionName);
			break;
		case EQUIP_STEP_ONE:
			MenuController.setEquipPosMenu(pm, actionName);
			break;
		case EQUIP_STEP_TWO:
			pm.getPlayerData().getActionMap().set(pm.getPlayerData().getActionSet().findActionInfo(actionName).getAction(), pm.getCurrentOption(), pm.getCurrentDepth());
			pm.regenerateSpinnerPreview();
			MenuController.setMainMenu(pm);
			break;
		case ADD_DEPTH:
			pm.getPlayerData().getActionMap().increaseDepth();
			//pm.getPlayerData().getActionMap().set(pm.getPlayerData().getActionSet().findActionInfo("Move").getAction(), 0, pm.getPlayerData().getActionMap().getDepth());
			break;
		case ADD_RADIUS:
			pm.getPlayerData().getActionMap().increaseRadius();
			break;
		case REDUCE_DEPTH:
			pm.getPlayerData().getActionMap().decreaseDepth();
			break;
		case REDUCE_RADIUS:
			pm.getPlayerData().getActionMap().decreaseRadius();
			break;
		case SET_DEFAULT_ACTION_MAP:
			pm.getPlayerData().setDefaultActionMap();
			break;
		case NEXT_UNIT:
			pm.getPlayerData().selectNextUnit();
			pm.regenerateSpinnerPreview();
			break;
		case CHANGE_COLOR:
			double rand = Math.random()*2*Math.PI;
			int r = (int)(Math.sin(rand)*127)+128%255;
			int g = (int)(Math.sin(rand+2)*127)+128%255;
			int b = (int)(Math.sin(rand+4)*127)+128%255;
			pm.getPlayerData().setPlayerColor(new Color(r, g, b));
			//pm.getPlayerData().setPlayerColor(new Color((int)(Math.random()*255), (int)(Math.random()*255), (int)(Math.random()*255)));
			pm.regenerateSpinnerPreview();
			break;
		default:
			System.out.println("not implemented");
		}
	}
	
	/**
	 * Paints a square representation of the action.
	 * @param bounds
	 * @param g
	 */
	public void paint(Rectangle bounds, MenuSelectionStatus status, Graphics g){
		g.setColor(color);
		g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
		g.setColor(Color.black);
		g.setFont(Constants.defaultFont);
		g.drawString(shownName, bounds.x+4, bounds.y+bounds.height-4);
		Color borderColor=Color.black;
		int borderWidth=0;
		
		switch(status){
		case DESELECTED:
			borderColor=Color.black;
			borderWidth=2;
			break;
		case ROW:
			borderColor=Color.green;
			borderWidth=2;
			break;
		case SELECTED:
			borderColor=Color.blue;
			borderWidth=4;
			break;		
		}
		g.setColor(borderColor);
		for(int c=0; c<borderWidth; c++){
			g.drawRect(bounds.x+c, bounds.y+c, bounds.width-2*c, bounds.height-2*c);
		}
	}
}
